package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import java.util.*;
import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Safetydocs entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "safetydocs", catalog = "bms")
public class Safetydocs implements java.io.Serializable {

	// Fields

	private Integer id;
	private Droga droga;
    private Date fecha;
    private String asuntoMail;
    private Collection<Envios> envioses = new ArrayList<Envios>(0);
    private Set<Compromisopais> countries = new HashSet<Compromisopais>(0);
    private Set<Role> roles = new HashSet<Role>(0);

    private List<SafetyRecipient> recipients = new ArrayList<SafetyRecipient>();

    private Boolean sentToPpalInv;
    private Boolean sentToSubInv;

    // Constructors

	/** default constructor */
	public Safetydocs() {
	}

	/** minimal constructor */
	public Safetydocs(Droga droga) {
		this.droga = droga;
	}

	/** full constructor */
	public Safetydocs(Droga droga, Collection<Envios> envioses, Date fecha, String asuntoMail, Boolean sentToPpalInv, Boolean sentToSubInv) {
		this.droga = droga;
		this.envioses = envioses;
        this.fecha = fecha;
        this.asuntoMail = asuntoMail;
        this.sentToPpalInv = sentToPpalInv;
        this.sentToSubInv = sentToSubInv;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

    @Column(name="date")
    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    @ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "DROGAid", nullable = false)
	public Droga getDroga() {
		return this.droga;
	}

	public void setDroga(Droga droga) {
		this.droga = droga;
	}

    @Column(name = "asuntoMail")
    public String getAsuntoMail() {
        return asuntoMail;
    }

    public void setAsuntoMail(String asuntoMail) {
        this.asuntoMail = asuntoMail;
    }

    @Column(name = "sentToPpalInv")
    public Boolean getSentToPpalInv() {
        return sentToPpalInv;
    }

    public void setSentToPpalInv(Boolean sentToPpalInv) {
        this.sentToPpalInv = sentToPpalInv;
    }

    @Column(name = "sentToSubInv")
    public Boolean getSentToSubInv() {
        return sentToSubInv;
    }

    public void setSentToSubInv(Boolean sentToSubInv) {
        this.sentToSubInv = sentToSubInv;
    }

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "safetydocs")
    @LazyCollection(LazyCollectionOption.FALSE)
	public Collection<Envios> getEnvioses() {
		return this.envioses;
	}

	public void setEnvioses(Collection<Envios> envioses) {
		this.envioses = envioses;
	}

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "compromisopais_safetydocs", catalog = "bms", joinColumns = { @JoinColumn(name = "id_safetydocs", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_compromisopais", nullable = false, updatable = false) })
    @LazyCollection(LazyCollectionOption.FALSE)
    public Set<Compromisopais> getCountries() {
        return countries;
    }

    public void setCountries(Set<Compromisopais> countries) {
        this.countries = countries;
    }

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "role_safetydocs", catalog = "bms", joinColumns = { @JoinColumn(name = "id_safetydocs", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_role", nullable = false, updatable = false) })
    @LazyCollection(LazyCollectionOption.FALSE)
    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "safetydocs")
    @LazyCollection(LazyCollectionOption.FALSE)
    public List<SafetyRecipient> getRecipients(){
        return recipients;
    }

    public void setRecipients(List<SafetyRecipient> recipients){
        this.recipients = recipients;
    }

    public boolean equals(Object o){
        Safetydocs otro = (Safetydocs)o;
        return this.id.equals(otro.id);
    }


}